package com.test.testapp.app;

import android.os.AsyncTask;

import org.json.JSONArray;
import org.json.JSONObject;

import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import static com.test.testapp.app.RDW.getJSONfromURL;

public abstract class parserTask extends AsyncTask<Void, Void, ArrayList<String>>
{
    private String kenteken;
    public parserTask(String kenteken) {
        this.kenteken = kenteken;
    }

    @Override
    protected ArrayList doInBackground(Void... params) {

        ArrayList gegevens = new ArrayList();
        try{
            String urlString = "http://rdw.almere.pilod.nl/kentekens/"+kenteken;
            URL url = new URL(urlString);//27kdx1");
            List infoList = new ArrayList();
            //   String aantalCilinders = "Cilinders";
            JSONArray user = null;
            JSONObject json;
            json = new JSONObject(getJSONfromURL(url.toString()));
            JSONObject resource = json.getJSONObject("resource");

            Iterator<String> keys = resource.keys();
            while (keys.hasNext())
            {
                String obj = keys.next();
                String keyValuePair = obj +": "+ resource.getString(obj);
                System.out.println(keyValuePair);
                gegevens.add(keyValuePair);

            }


        }
        catch(Exception e)
        {
            System.out.println(e.toString());
        }
        return gegevens;

    }

    protected abstract void onPostExecute(ArrayList result);

    /**
     public  class info
     {
     public  info (List gegevens)
     {
     ListView kentList = (ListView)findViewById(R.id.getInfo);
     kentList.setAdapter((ListAdapter) gegevens);
     }
     public void run(List gegevens)
     {
     ListView kentList = (ListView)findViewById(R.id.getInfo);
     kentList.setAdapter((ListAdapter) gegevens);
     }
     }*/
}
